package Classic150;

import Tree.TreeNode;

public class 二叉搜索树的最小绝对差 {

    int min = Integer.MAX_VALUE;
    TreeNode pre = null;

    /*
        中序遍历利用二叉搜索树性质
     */
    public int getMinimumDifference(TreeNode root) {
        inorder(root);
        return min;
    }

    private void inorder(TreeNode root) {
        if (root == null) return;
        inorder(root.left);
        if (pre != null) min = Math.min(min, root.val - pre.val);
        pre = root;
        inorder(root.right);
    }
}
